package work3_13;

import java.util.Objects;

public class Test2 {
    /**
     * 2.声明一个 Person类，
     * 在其中声明 name 、age 、 gender 等私有字段，
     * 并声明 有参构造 和 getter、setter。
     */
    private String name;
    private int age;
    private String gender;

    public Test2(String name, int age, String gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public Test2() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
    //重写compareTo方法
    public int compareTo(Object O) {
        Test2 t = (Test2) O;
        return this.getAge() - t.getAge();
    }

    @Override
    public String toString() {
        return "test2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o){ return true;}
        if (o == null || getClass() != o.getClass()){ return false;}
        Test2 test2 = (Test2) o;
        return age == test2.age && Objects.equals(name, test2.name) && Objects.equals(gender, test2.gender);
    }


    @Override
    public int hashCode() {
        return Objects.hash(name, age, gender);
    }
}
